package com.day12.study.thread_demo;

/**
 * 死锁练习
 *
 * @author Twinkle
 */
public class DeadLock {
    public static void main(String[] args) {
        Counter c = new Counter();
        new Thread(() -> {
            c.m1();
        }).start();
        new Thread(() -> {
            c.m2();
        }).start();
    }
}

class Counter {
    private final static Object lockA = new Object();
    private final static Object lockB = new Object();

    public void m1() {
        synchronized (lockA) {
            System.out.println("aa");
            synchronized (lockB) {
                System.out.println("bb");
            }
        }
    }

    public void m2() {
        synchronized (lockB) {
            System.out.println("11");
            synchronized (lockA) {
                System.out.println("22");
            }
        }
    }
}
